home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0094_String Dumps.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-25  |  4KB  |  109 lines

  1. {
  2. LH>    Very nice - and a dandy tutorial on OOP streaming.
  3.  
  4. Thanks for the compliment.
  5.  
  6. LH>    My little step-up speeds things up by 3x, but I imagine yours is
  7. LH>    a hefty margin faster than that.
  8.  
  9. I further modified the original and my streaming version to send their
  10. outputs to a text file. In the original I used a variable of type
  11. Text, and in the streaming version, I used a variable of type
  12. pBufStream. This was to eliminate any screen scrolling delays. I ran
  13. both versions on COMMAND.COM, which has a file size of 47845 bytes on
  14. my system. In going back over my code, I also noticed that I had
  15. declared the read buffer as vInByte: BYTE. I changed this to vInChar:
  16. CHAR and eliminated the call to Chr(vInByte) when appending characters
  17. to the result string.
  18.  
  19. The original took 243201.838 ms and the streaming version took
  20. 2351.532 ms to scan the file. The absolute numbers are less important
  21. than the ratio, which is 103.423. So in this instance the use of
  22. streams and in-memory searching resulted in a speed-up of almost 104x.
  23.  
  24. I tried buffer sizes of 512 to 16384 bytes in increments of 512 bytes
  25. and found that 8192 was optimum on my system. The worst buffer size
  26. was 1024 bytes. This required 2765.426 ms to scan the file, an
  27. increase of 17.6% over the optimum. This was a very interesting and
  28. unexpected result, given that 1024 is the figure used in the TV and
  29. OWL documentation. Of course, this is probably very system dependent.
  30. I run dual IDE drives, one formatted FAT and the other formatted OS/2
  31. HPFS. The above results were obtained off the FAT drive. 
  32.  
  33. On the HPFS drive, the best time was turned in by a buffer size of
  34. 4608 bytes. This size had given the second-best results on the FAT
  35. drive at 2368.464 ms, but clocked in on the HPFS drive at 2373.780.
  36. Using an 8192 byte buffer on the HPFS drive resulted in a time of
  37. 2449.082 ms.
  38.  
  39. Comparing the speeds on the FAT and HPFS drives in this case isn't
  40. really apples and apples, since the two drives are from different
  41. manufacturers. A better test would be to use two logical partitions on
  42. the same drive. Even at that though the average boost in speed was
  43. around 100x over the original.
  44. }
  45. PROGRAM FindStr;
  46.  (* Searches any file for printable strings of 6 or more characters. *)
  47.  (* Useful for extracting messages and internal documentation from .EXE's *)
  48.  
  49.  USES
  50.    Objects;
  51.  
  52.  VAR
  53.    vInFile,
  54.    vOutFile : pBufStream;
  55.    vMemFile : pMemoryStream;
  56.    vS       : STRING;
  57.    vInChar  : CHAR;
  58.  BEGIN
  59.    vInFile := New(pBufStream, Init(ParamStr(1), stOpenRead, 8192));
  60.    IF vInFile = NIL THEN
  61.      BEGIN
  62.        WriteLn('Unable to open input file');
  63.        Halt;
  64.      END;
  65.    vOutFile := New(pBufStream, Init(ParamStr(2), stCreate, 8192));
  66.    IF vOutFile = NIL THEN
  67.      BEGIN
  68.        WriteLn('Unable to create output file');
  69.        Dispose(vInFile, Done);
  70.        Halt;
  71.      END;
  72.    vMemFile := New(pMemoryStream, Init(vInFile^.GetSize, 8192));
  73.    IF vMemFile = NIL THEN
  74.      BEGIN
  75.        WriteLn('Insufficient memory');
  76.        Dispose(vInFile, Done);
  77.        Dispose(vOutfile, Done);
  78.        Halt;
  79.      END;
  80.    vInFile^.Seek(0);
  81.    vOutFile^.Seek(0);
  82.    vMemFile^.CopyFrom(vInFile^, vInFile^.GetSize);
  83.    IF vInFile <> NIL THEN
  84.      Dispose(vInFile, Done);
  85.    vMemFile^.Seek(0);
  86.    WriteLn('>>Searching ', ParamStr(1),'<<');
  87.    WITH vMemFile^ DO
  88.      WHILE (Status = stOK) DO
  89.        BEGIN
  90.          vS := '';
  91.          Read(vInChar, 1);
  92.          WHILE ((vInChar > #31) AND (vInChar < #127) AND (Status = stOK)) DO
  93.            BEGIN
  94.              vS := vS + vInChar;
  95.              Read(vInChar, 1);
  96.            END;
  97.            IF Length(vS) > 5 THEN
  98.              BEGIN
  99.                vS := vS + #13#10;
  100.                vOutFile^.Write(vS[1], Length(vS));
  101.              END;
  102.        END;
  103.    IF vMemFile <> NIL THEN
  104.      Dispose(vMemFile, Done);
  105.    IF vOutFile <> NIL THEN
  106.      Dispose(vOutFile, Done);
  107.    WriteLn('>>End of file<<');
  108.  END.
  109.